package fun.boomcat.luckyhe.mirai.plugin.botcontrol.util;

import net.mamoe.mirai.console.command.CommandSender;

import java.util.Arrays;

/**
 * @author Lucky_He
 * @date 2021年9月8日 15:18
 * @description DirectChattingOperation
 */
public class DirectChattingOperation {
    public static void directChattingOperation(CommandSender commandSender, Object[] args, String primaryName) {
        int len = args.length;
        String operation = args[0].toString();

        switch (operation.toLowerCase()) {
            case "set":
            case "设置":
                set(commandSender, Arrays.copyOfRange(args, 1, len), primaryName);
                break;

            case "reset":
            case "重置":
                reset(commandSender, primaryName);
                break;

            default:
                commandSender.sendMessage(ControlCommandHelp.directChattingHelp(primaryName));
                break;
        }
    }

    private static void set(CommandSender commandSender, Object[] args, String primaryName) {
        long qq, groupId;
        try {
            qq = Long.parseLong(args[0].toString());
            groupId = Long.parseLong(args[1].toString());
        } catch (Exception e) {
            commandSender.sendMessage("错误：" + e.toString());
            return;
        }

        CurrentChattingUtil.set(qq, groupId);
        commandSender.sendMessage("设置完成：\nQQ：" + qq + "\n群号：" + groupId + "\n类型：" + CurrentChattingUtil.getType().getName());
    }

    private static void reset(CommandSender commandSender, String primaryName) {
        CurrentChattingUtil.reset();
        commandSender.sendMessage("重置完成，现在不再与任何用户进行直接对话");
    }
}
